<!-- 利润激励  -->
<template>
    <div class="profitIncentive">
        <div>
            创建时间：
            <el-date-picker
                    v-model="searchTime"
                    type="daterange"
                    align="right"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :picker-options="pickerOptions">
            </el-date-picker>
            <el-button type="primary" @click="searchDataByTime" id="monitorEnter">查询</el-button>
            <el-button type="primary" @click="newPage('new', false)">新建</el-button>
        </div>
        <el-table
                :data="tableData"
                highlight-current-row
                style="width: 100%;margin-top: 20px;">
            <el-table-column
                    type="index"
                    label="序号"
                    width="50">
            </el-table-column>
            <el-table-column
                    property="version"
                    align="center"
                    label="版本号">
            </el-table-column>
            <el-table-column
                    property="extractStandard"
                    align="center"
                    label="计提标准"
                    width="120">
                <template slot-scope="scope">
                    {{extractStandard[scope.row.extractStandard]}}
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    property="groupProportion"
                    label="集团计提比例"
                    width="120">
                <template slot-scope="scope">{{scope.row.groupProportion}}%</template>
            </el-table-column>
            <el-table-column
                    align="center"
                    property="easylifeProportion"
                    label="好生活应发占比">
                <template slot-scope="scope"><a href="javascript:;" @click="viewInterval(scope.row.departmentList)">{{scope.row.easylifeProportion}}%</a>
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    property="createTime"
                    label="创建时间">
            </el-table-column>
            <el-table-column
                    align="center"
                    property="creatorName"
                    label="创建人">
            </el-table-column>
            <el-table-column
                    width="100"
                    align="center"
                    label="详细信息">
                <template slot-scope="scope">
                    <a href="javascript:;;" @click="newPage('view', scope.row.id)">查看</a>
                    <a href="javascript:;;" @click="newPage('edit', scope.row.id)">编辑</a>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagebar">
            <el-pagination
                    background
                    layout="total, sizes, prev, pager, next, jumper"
                    :current-page.sync="tableConfig.pageNum"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="tableConfig.pageSize"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :total="tableConfig.totalSize">
            </el-pagination>
        </div>
        <el-dialog
                title="查看好生活应发占比"
                :visible.sync="intervalDialogVisible"
                width="500px">
            <div class="profitIncentiveTable">
                <el-table
                        :data="classificationTableData"
                        border
                        highlight-current-row
                        style="width: 100%;margin-top: 20px; max-height:450px; overflow: auto;">
                    <el-table-column
                            type="index"
                            width="50"
                            align="center"
                            label="序号">
                    </el-table-column>
                    <el-table-column
                            property="departmentName"
                            align="center"
                            label="部门">
                    </el-table-column>
                    <el-table-column
                            property="departmentProportion"
                            align="center"
                            label="分配比例">
                        <template slot-scope="scope">{{scope.row.departmentProportion}}%</template>
                    </el-table-column>
                </el-table>
            </div>
            <span slot="footer">
                <el-button @click="intervalDialogVisible = false">关闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import api from '@/api/apiPath'
    import {extractStandard} from "../fieldMap"

    export default {
        name: "profitIncentive",
        title:'利润激励标准',
        data() {
            return {
                searchTime: "",
                tableConfig: {
                    startTime: "",
                    endTime: "",
                    pageNum: 1,
                    pageSize: 10,
                    totalSize: 10
                },
                classificationTableData: [
                    {
                        name: '王小虎',
                        address: '上海市普'
                    }
                ],
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                intervalDialogVisible: false,
                tableData: [],
                extractStandard
            }
        },
        created() {
            this.getProdrawStandardList()
        },
        activated(){
            this.searchDataByTime()
        },
        mounted() {

        },
        methods: {
            searchDataByTime() {
                if (this.searchTime === null) {
                    this.searchTime = ["", ""]
                }
                if (this.searchTime.length) {
                    this.tableConfig.startTime = +new Date(this.searchTime[0])
                    this.tableConfig.endTime = +new Date(this.searchTime[1])
                }
                this.tableConfig.pageNum = 1;
                this.getProdrawStandardList();
            },
            newPage(type, id) {
                let query = {
                    type
                };
                if (id) {
                    query['id'] = id;
                }
                this.$router.push({path: "./profitIncentiveHandle", query: query})
            },
            viewInterval(departmentList) {
                this.intervalDialogVisible = true;
                this.classificationTableData = departmentList
            },

            getProdrawStandardList() {
                this.axios.post(api.getProdrawStandardList, {
                    startTime: this.tableConfig.startTime,
                    endTime: this.tableConfig.endTime,
                    pageNum: this.tableConfig.pageNum,
                    pageSize: this.tableConfig.pageSize
                }).then((res) => {
                    console.log(res.data.data.list);
                    this.tableData = res.data.data.list;
                    this.tableConfig.totalSize = res.data.data.total;
                })
            },
            handleSizeChange(size) {
                this.tableConfig.pageSize = size
                this.getProdrawStandardList()
            },
            handleCurrentChange(page) {
                this.tableConfig.pageNum = page
                this.getProdrawStandardList()
            },
        },
        components: {},
        computed: {}
    }
</script>

<style scoped>
    .profitIncentiveTable .el-table::before{
        height: 0;
    }
</style>




